#ifndef CX_HAL_TIMER_H
#define CX_HAL_TIMER_H
#include "at32f415.h"
#include "cx_typedef.h"
typedef tmr_type *cx_hal_timer_controller_t;
typedef struct cx_hal_timer_handle
{
    cx_hal_timer_controller_t controller;
    cx_uint32_t clock_in;
    cx_uint32_t counterPerPeriod;
    cx_uint32_t usPerCounter;
}cx_hal_timer_handle_t;

typedef union
{
    struct
    {
        cx_intr_cb_t update;
        cx_intr_cb_t trigger;
        cx_intr_cb_t hall;
    }member;
    cx_intr_cb_t group[3];
}timer_intr_cb_t;

#ifdef CX_HAL_TIMER_ENABLE_INTERRUPT_MANAGER
typedef enum
{
    CX_HAL_TIMER_INTR_UPDATE,
    CX_HAL_TIMER_INTR_TRIGGER,
    CX_HAL_TIMER_INTR_HALL
}cx_hal_timer_intr_t;
cx_err_t cx_hal_timer_intr_init(void);
cx_err_t cx_hal_timer_attachInterrupt(cx_hal_timer_handle_t *handle, cx_intr_cb_t cb, cx_hal_timer_intr_t cx_hal_timer_intr_type);
cx_err_t cx_hal_timer_detachInterrupt(cx_hal_timer_handle_t *handle, cx_hal_timer_intr_t cx_hal_timer_intr_type);
#endif
cx_err_t cx_hal_timer_set_period(cx_hal_timer_handle_t *handle,cx_uint32_t Hz);
cx_err_t cx_hal_timer_cmd(cx_hal_timer_handle_t *handle,cx_FunctionalState_t cx_State);
#endif
